1. Field of Invention
The present invention relates generally to object-based computing systems. More particularly, the present invention relates to storing objects in compressed formats on memory heaps within an object-based computing system.
2. Description of the Related Art
The use of computer systems which share resources across a network of computer systems, e.g., local area networks, intranets and internets, is increasing. To facilitate the sharing of resources, objects are often implemented within computer systems. Object-based computing systems are often arranged such that objects may be shared between different processes on a network.
An object typically includes a set of operations and a state which essentially xe2x80x9cremembersxe2x80x9d the effect of the operations. In general, an object may be considered to be one form of a function that includes memory. FIG. 1 is a diagrammatic representation of a conventional object. An object 102 includes a header 104 and multiple data fields 108. Header 104 is typically a word that stores object-related information. The object-related information often includes other information such as hash values that identify the object and garbage collection information.
Data fields 108 may contain substantially any data which may be used by a process when the process invokes object 104. Data fields 108 typically include fields which hold integer data, e.g., field 108a, fields which hold character data, e.g., field 108b, and fields which hold pointers, e.g., fields 108c and 108d. In general, as will be appreciated by those skilled in the art, most fields 108 within object 102 are pointer fields which contain pointers to other objects.
Integer field 108a is typically four bytes long, i.e., integers contained within integer field 108a occupy four bytes, while character field 108b is typically two bytes long, i.e., characters contained within character field 108b occupy two bytes. Pointer field 108c is arranged to include an address of a different object that is referenced by object 102. The address, or pointer, contained within pointer field 108c generally occupies four bytes. In other words, pointer field 108c is four bytes long.
Memory space in computing systems such as object-based systems is often limited. In particular, objects which are allocated by and used by programs generally occupy a significant portion of the memory required to execute a program. A computing system that is capable of executing multiple applications may suffer a failure when there is not enough memory available to execute a necessary application or program. In addition, an application or a program may not run as expected, e.g., may run slowly, when insufficient memory is available to that application or program. That is, when the memory required to execute a program exceeds the size of a cache, the program may execute significantly slower than expected.
Although it may be possible to add more memory to some computing systems in order to alleviate memory issues, adding memory to other systems may be impractical and, in some cases, physically impossible. For example, for a small device such as a hand-held computing device, a personal digital assistant, or a cell phone, there is often not enough space within the device to accommodate additional memory.
Reducing the amount of memory required to enable a program to run would result in better performance of the program and, potentially, other programs since more memory would conceivably be available for use by the other programs. Therefore, what is desired is an efficient method and apparatus for reducing the amount of memory consumed by a program.
The present invention relates to a heap structure which includes a heap for full-size objects and a heap for reduced-size objects. Using reduced-size objects reduces the amount of memory used by applications or programs executing within an object-based computing system, thereby increasing the performance associated with the object-based computing system. According to one aspect of the present invention, a method for creating a compressed version of an object that stores a first representation of a set of data on a heap structure of an object-based computing system includes determining when the first representation of the set of data is suitable for compression. If the first representation of the set of data is compressible, it is compressed to form a second representation of the set of data, and a second portion of memory is allocated on the heap structure. The second portion of memory is substantially smaller than the amount of memory occupied by the object, e.g., is smaller than a first portion of memory occupied by the object. Finally, the method includes writing the second representation of the set of data into the allocated second portion of memory. In one embodiment, the method includes resetting a pointer that identifies the object to identify the allocated second portion of memory, and removing the object from the heap structure.
In a second embodiment, the allocated second portion of memory is a compressed object, and the method also includes writing information into a field associated with the compressed object. In such an embodiment, writing the information includes determining when the information is compressible, and allocating a third portion of memory on the heap structure when the information is not compressible. The allocated third portion of memory is substantially larger than the compressed object. A pointer is set to find the allocated third portion of memory from the compressed object, and the second representation of the data is stored into the allocated third portion of memory. Then, the information is stored into the allocated third portion of memory at an appropriate field.
According to another aspect of the present invention, a method for performing garbage collection within an object-based computing system includes traversing at least one heap structure associated with the object-based computing system, and copying an object that is located on the heap structure. The object includes a first representation of a set of information, and copying the object includes determining when the object may be represented as a compressed format object that is substantially smaller in size than the object. In one embodiment, determining when the object may be represented as the compressed format object includes determining when a second representation of the set of information may be created as a compressed version of the first representation.
In another embodiment, copying the object involves creating the second representation of the set of information by reducing the number of bytes associated with the set of information, and allocating memory space on the heap structure. The amount of memory space allocated is less than an amount of memory space associated with the object. The second representation may then be stored in the memory space allocated on the heap structure.
According to still another embodiment of the present invention, a memory for storing objects within an object-based computing system includes a first heap and a second heap. The first heap stores an uncompressed object of a first size, and includes a first representation of an amount of information. The second heap stores a compressed object of a second size, and includes a second representation of the amount of information. The second size is substantially smaller than the first size. In one embodiment, the second size is in the range of approximately one fourth to approximately one half the size of the first size.
In another embodiment, the first representation includes a reference to an object stored within the memory. In such an embodiment, the reference may be an address location of the object and the second representation may include a reference to the object that is represented as a difference between the address location of the first object and an address location of the compressed object.